package sapling.api;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sapling.dao.CostDao;
import sapling.model.Cost;
import sapling.utils.Msg;

import java.util.Date;
import java.util.List;

/**
 * Created by mac on 17/7/11.
 */
@RestController
@RequestMapping("/api/cost")
public class CostApi {

    @Autowired
    CostDao costDao;

    @ApiOperation(value = "录入成本", notes = "waterrate:水费, chemical:电费,medicine:农药 landrent:地租, personrate:人工费")
    @PostMapping("/entering")
    public Msg<Cost> die(@RequestParam double waterrate, @RequestParam double chemical, @RequestParam double medicine, @RequestParam double landrent, @RequestParam double personrate){
        Cost cost=new Cost();
        cost.setWaterrate(waterrate);
        cost.setLandrent(landrent);
        cost.setPersonrate(personrate);
        cost.setEnteringTime(new Date());
        cost.setChemical(chemical);
        cost.setMedicine(medicine);
        costDao.save(cost);
        return Msg.newMsg(cost);
    }
    @ApiOperation(value = "录入成本", notes = "waterrate:水费, chemical:电费,medicine:农药 landrent:地租, personrate:人工费")
    @PostMapping("/entering2")
    public Msg<String> ent2(@RequestParam double waterrate, @RequestParam double chemical, @RequestParam double medicine, @RequestParam double landrent, @RequestParam double personrate){
        Cost cost=new Cost();
        cost.setWaterrate(waterrate);
        cost.setLandrent(landrent);
        cost.setPersonrate(personrate);
        cost.setEnteringTime(new Date());
        cost.setChemical(chemical);
        cost.setMedicine(medicine);
        costDao.save(cost);
        return Msg.newMsg("success");
    }

    @ApiOperation(value = "获取成本列表成本", notes = "获取录入的所有成本")
    @GetMapping("/acquire")
    public Msg<List<Cost>> acquire(){
        return Msg.newMsg(costDao.findAll());
    }
}
